package cn.itsource.wechart.controller;

import cn.itsource.basic.util.AjaxResult;
import cn.itsource.wechart.pojo.domain.WechartProperties;
import cn.itsource.wechart.pojo.dto.BinderDto;
import cn.itsource.wechart.service.IWeChartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/wechart")
public class WeChartController {

    @Autowired
    private WechartProperties wechartProperties;

    @Autowired
    private IWeChartService weChartService;


    /**
     * 点页面的”微信登录“进来的
     *
     * @return
     */
    @GetMapping("/tologin")
    public String toLogin() {
        return weChartService.toLogin();
    }

    /**
     * 扫码进来的
     *
     * @param code
     */
    @GetMapping("callback")
    public String callback(String code) {
        //调用service
        return weChartService.callback(code);
    }

    /**
     * 绑定的接口
     */
    @PostMapping("/binder")
    @ResponseBody
    public AjaxResult binder(@RequestBody BinderDto binderDto) {
        //调用service
       return weChartService.binder(binderDto);
    }


    @RequestMapping("/test")
    public void test() {

        System.err.println(wechartProperties);

    }


    public static void main(String[] args) {
        //解耦
        String appid = "wxd853562a0548a7d0";

        String appsecrect = "4a5d5615f93f24bdba2ba8534642dbb6";
        String url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=%s&secret=%s";

        // %s：占位符
        String format = String.format(url, appid, appsecrect);
        System.out.println(format);
        //https://api.weixin.qq.com/sns/oauth2/access_token?appid=wxd853562a0548a7d0&secret=4a5d5615f93f24bdba2ba8534642dbb6
    }
}
